using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using UnityEngine;

public class SerilaizerableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, IXmlSerializable
{
    public XmlSchema GetSchema()
    {
        return null;
    }

    public void ReadXml(XmlReader reader)
    {
        XmlSerializer key = new XmlSerializer(typeof(TKey));
        XmlSerializer value = new XmlSerializer(typeof(TValue));
        reader.Read();
        while (reader.NodeType != XmlNodeType.EndElement)
        {
            TKey tk=(TKey)key.Deserialize(reader);
            TValue tv=(TValue)value.Deserialize(reader);
            this.Add(tk, tv);
        }
        reader.Read();
    }

    public void WriteXml(XmlWriter writer)
    {
        XmlSerializer key=new XmlSerializer(typeof(TKey));
        XmlSerializer value=new XmlSerializer(typeof(TValue));
        foreach(KeyValuePair<TKey, TValue>dic in this)
        {
            key.Serialize(writer, dic.Key);
            value.Serialize(writer, dic.Value);
        }
    }
}
